﻿using System;
using System.Collections.Generic;
using System.Text;

namespace Slippor.Common.PluginFramework
{
    public class VersionAttribute : Attribute, IVersion
    {
        public Version Version { get { return _version.Version; } }
        private IVersion _version = null;

        public bool IsVersionable
        {
            get { return _version != null && _version.IsVersionable; }
        }

        public VersionAttribute(String version)
        {
            _version = new BasicVersion(version);
        }

        public VersionAttribute(Type type, params object[] args)
        {
            if (args == null)
            {
                _version = Activator.CreateInstance(type) as IVersion;
            }
            else
            {
                _version = Activator.CreateInstance(type, args) as IVersion;
            }
        }

        public string Description
        {
            get { return _version.Description; }
        }

        public void GetLatestVersionAsync()
        {
            _version.GetLatestVersionAsync();
        }

        public event EventHandler<PluginVersionEventArgs> GetLatestVersionCompleted
        {
            add { _version.GetLatestVersionCompleted += value;}
            remove { _version.GetLatestVersionCompleted -= value; }
        }

        public void UpdateAsync()
        {
            _version.UpdateAsync();
        }

        public event EventHandler<UpdateEventArgs> UpdateCompleted
        {
            add { _version.UpdateCompleted += value; }
            remove { _version.UpdateCompleted -= value; }
        }
    }
}
